#define _CRT_SECURE_NO_WARNINGS
#pragma once
#include<string>
#include<assert.h>
#include<iostream>
namespace fast
{
	class string
	{
	public:
		string(const char* str = "")
		{
			_size = strlen(str);
			_capacity = _size;
			_str = new char[_capacity + 1];
			strcpy(_str, str);
		}
		~string()
		{
			delete[] _str;
			_str = nullptr;
			_size = 0;
			_capacity = 0;
		}
		typedef char* iterator;
		typedef const char* const_iterator;
		const_iterator begin() const
		{
			return _str;
		}
		const_iterator end() const
		{
			return _str + _size;
		}
		iterator begin()
		{
			return _str;
		}
		iterator end()
		{
			return _str + _size;
		}

		const char* c_str() const
		{
			return _str;
		}
		size_t size() const
		{
			return _size;
		}


		char& operator[](size_t pos)
		{
			assert(pos <= _size);
			return _str[pos];
		}
		const char& operator[](size_t pos) const
		{
			assert(pos <= _size);
			return _str[pos];
		}
		
		void push_back(char ch);
		void append(const char* str);
		string& operator+=(char ch);
		string& operator+=(const char* str);
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
	};
	void test_string(const string& s)
	{
		for (size_t i = 0; i < s.size(); ++i)
		{
			std::cout << s[i] << " ";
		}
		std::cout << s.c_str() << std::endl;
		string::const_iterator sit = s.begin();
		while (sit != s.end())
		{
			std::cout << *sit << " ";
			++sit;
		}
	}

	void test_string1()
	{
		//string s1("hello");
		//std::cout << s1.c_str() << std::endl;
		//for (int i = 0; i < s1.size(); ++i)
		//{
		//	s1[i]++;
		//}
		//std::cout << s1.c_str() << std::endl;
		string s1("hello world");
		string::iterator sit = s1.begin();
		while (sit != s1.end())
		{
			std::cout << *sit << " ";
			++sit;
		}
		std::cout << std::endl;
	}
}

